/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_API_COLLECTIONS_MANAGER_HPP
#define	_CUBEFS_API_COLLECTIONS_MANAGER_HPP

#include <cubefs/api/metadata/metadata.hpp>
#include <cubefs/api/reflection.hpp>

#include <cubefs/api/models/container.hpp>
#include <cubefs/api/models/logs.hpp>

namespace cubefs    {
namespace api       {

struct CUBEFS_API Manager: public Container {

	enum {NONE = 0, ROOT = 1};

	virtual Page* CreatePageWrapper()					= 0;
	virtual void GetRootPageId(TypedIDValue* id)		= 0;
	virtual void SetRootPageId(TypedIDValue* id)		= 0;
    virtual void GetPage(Page* page, TypedIDValue* id) 	= 0;
    virtual void RemovePage(TypedIDValue* id) 			= 0;
    virtual void CreateNewPage(int flags, Page* page)   = 0;

    virtual BigInt GetPageCount()       				= 0;
    virtual Logger& logger() 							= 0;
    virtual Logger* GetLogger()							= 0;

    virtual Container* GetContainer()					= 0;
    virtual void SetContainer(Container* container)		= 0;

    static Type* MyType();
};

CUBEFS_DECLARE_TYPENAME(Manager,    "cubefs::api::models::Manager");

struct CUBEFS_API InputStreamHandler: public Typed {
    virtual Int available() 							= 0;
    virtual void close() 								= 0;
    virtual Int buffer_size() 							= 0;
    virtual Int read(void* mem, Int offset, Int length) = 0;
    virtual bool read(void* mem, Int size)				= 0;


    template <typename T>
    bool read(T &value) {
        return read(&value, sizeof(T));
    }

    static Type* MyType();
};

CUBEFS_DECLARE_TYPENAME(InputStreamHandler,    "cubefs::api::models::InputStreamHandler");

struct CUBEFS_API OutputStreamHandler: public Typed {

    virtual Int buffer_size() = 0;
    virtual void flush() = 0;
    virtual void close() = 0;
    virtual void write(const void* mem, int offset, int lenght) = 0;

    template <typename T>
    void write(const T& value) {
        write(&value, 0, sizeof(T));
    }

    static Type* MyType();
};

CUBEFS_DECLARE_TYPENAME(OutputStreamHandler,    "cubefs::api::models::OutputStreamHandler");

struct CUBEFS_API StreamManager: public Manager {
    virtual void load(InputStreamHandler *input) = 0;
    virtual void store(OutputStreamHandler *output) = 0;

    static Type* MyType();
};

CUBEFS_DECLARE_TYPENAME(StreamManager,    "cubefs::api::models::StreamManager");

}
}

#endif
